package 力扣91;

import java.util.HashMap;
import java.util.Map;

/**
 * @ClassName : Day_19_两数之和
 * @Author : 骆发茂
 * @Date: 2021/12/30 20:48
 * @Description : https://leetcode-cn.com/problems/two-sum/
 */
public class Day_19_两数之和 {
    class Solution {
        public int[]oSum(int[] nums, int target) {
            ///cun存的是下标
            int[] res = new int[2];
            if(nums ==null || nums.length==0){
                return res;
            }
            //map,第一个存值，第二个存下标
            Map<Integer,Integer> map = new HashMap<>();
            for(int i = 0; i<nums.length;i++){
                int temp = target-nums[i];
                if(map.containsKey(temp)){
                    res[1]=i;
                    res[0]=map.get(temp);

                }
                map.put(nums[i],i);
            }
            return res;
        }
    }
}